﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Specialized;
using System.Text;

namespace sqengine
{
    partial class sqengine : Microsoft.Xna.Framework.Game
    {
        private SqConsole sqconsole;

        private HybridDictionary _ingamevars = new HybridDictionary();

        public bool IsConsoleActive { get { return sqconsole.Active; } }

        public HybridDictionary GetInGameVars { get { return _ingamevars; } set { _ingamevars = value; } }

        public SqConsole Console { get { return sqconsole; } }


        public void ConsoleSetVar(string key, string value)
        {
            setgamevar(key, value);
        }


        public void ConsoleSetVar(string key, object value)
        {
            setgamevar(key, value.ToString());
        }

        public string ConsoleGetVar(string key)
        {
            string gamevar = getgamevar(key);


            return gamevar;

        }

        private string getgamevar(string key)
        {
            try
            {
                return _ingamevars[key].ToString();
            }
            catch
            {
                return "";
            }
        }

        private void setgamevar(string key, string value)
        {
            try
            {
                if (value == "")
                {
                    _ingamevars.Remove(key);
                }
                else
                {
                    _ingamevars.Add(key, value);
                }
            }
            catch
            {
                _ingamevars[key] = value;
            }

        }



        public void LoadConsole()
        {
            sqconsole = new SqConsole(this, adcontent, keyboardmanager);
            Components.Add(sqconsole);
            sqconsole.DrawOrder = 1;

            //inizialize game vars
            setgamevar(VAR_SQDEBUG, sqconfig.DebugMode.ToString());
            setgamevar(VAR_SQBOOTTIME, DateTime.Now.ToString());
            setgamevar(VAR_SQVERSION, SqEngine.SqEngineInfo._full_version);
        }

    }
}
